﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class ElectReport : BaseRepository<ElecPropertyInfo>, IElectReport
    {
        private const string PARM_TESTITEM_STRATDATE = "@starttime";
        private const string PARM_TESTITEM_ENDDATE = "@stoptime";

        public IList<ElecPropertyInfo> LoadEntities()
        {
            return null;
        }

        public ElecPropertyInfo LoadEntity<T1>(T1 Id)
        {
            return null;
        }

        public IList<ElecPropertyInfo> GetElecData(DateTime StartDate, DateTime EndDate)
        {
            //Create a parameter    
            SqlParameter[] testItemParms = GetSNTParameters();
            //Bind the parameter
            testItemParms[0].Value = StartDate;
            testItemParms[1].Value = EndDate;
            return ExcuteSqlToGetEntities("TTest_Elect_Report", testItemParms);
        }

        public IList<ElecPropertyInfo> GetElecData()
        {
            return ExcuteSqlToGetEntities("TTest_Elect_AllData");
        }


        #region 参数部分
        private static SqlParameter[] GetSNTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TESTITEM_STRATDATE, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TESTITEM_ENDDATE, SqlDbType.DateTime, 8)                
                };
            return parms;
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ElecPropertyInfo GetEntityRecord(SqlDataReader rdr)
        {
            ElecPropertyInfo pro = new ElecPropertyInfo
            {
                RecordDate = rdr.GetValue(0).ToString(),
                ProductTypeName = rdr.GetValue(1).ToString(),
                ProductTypeID = rdr.GetValue(2).ToString(),
                MOID = rdr.GetValue(3).ToString(),
                TestTotalCount = rdr.GetValue(4).ToString(),
                DayAmount = rdr.GetInt32(5),
                NightAmount = rdr.GetInt32(6),
                DayFailAmount = rdr.GetInt32(7),
                NightFailAmount = rdr.GetInt32(8),
                DayFailRate = rdr.GetValue(9).ToString(),
                NightFailRate = rdr.GetValue(10).ToString(),
                TotalFallCount = rdr.GetValue(11).ToString(),
                TotalFallRate = rdr.GetValue(12).ToString(),
                VSWRFailAmount = rdr.GetInt32(13),
                ISOFailAmount = rdr.GetInt32(14),
                ScopeFailAmount = rdr.GetInt32(15),
                PhaseFailAmount = rdr.GetInt32(16),
                SFailAmount = rdr.GetInt32(17),
                DFailAmount = rdr.GetInt32(18),
                BarCodeFailAmount = rdr.GetInt32(19), 
                RCUNum = rdr.GetInt32(20),
                WaveFailAmount = rdr.GetInt32(21),
                User = rdr.GetValue(22).ToString(),
                ShiftClass = rdr.GetValue(23).ToString(),
                ProductTypeSerialID = rdr.GetValue(24).ToString(),
                TestStep = rdr.GetValue(25).ToString(),
               
            };
            return pro;
        }
        #endregion
    }
}
